package com.zrq.jwtdemo.author.controller;


import com.zrq.jwtdemo.author.dto.request.UsersRequest;
import com.zrq.jwtdemo.author.dto.result.UsersListResult;
import com.zrq.jwtdemo.author.model.Users;
import com.zrq.jwtdemo.author.service.IUsersService;
import com.zrq.jwtdemo.core.constant.Constant;
import com.zrq.jwtdemo.core.result.APIResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.*;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
* <p>
    * 用户表 前端控制器
    * </p>
*
* @author zrq
* @since 2020-12-20
*/
@RestController
@RequestMapping("/author")
@AllArgsConstructor
@Validated
@Api(value = "用户管理控制器",tags = "用户管理控制器")
public class UsersController {

    private final IUsersService iUsersService;

    @GetMapping("/list")
    @ApiOperation(value = "查询用户列表")
    public APIResponse<List<UsersListResult>> getUserList(HttpServletRequest request) {
        return APIResponse.makeSuccess(iUsersService.getUserList(request));
    }

    @PostMapping("/insert_user")
    @ApiOperation(value = "添加用户")
    public APIResponse<String> insUser(@Validated UsersRequest request) {
        iUsersService.insUser(request);
        return APIResponse.makeSuccess(Constant.SUCCESS);
    }
}
